import { defineStore } from 'pinia';
// import { getProductPageList } from '@/api/productManage';
import { menu } from '@/menuConfig/menu';

// eslint-disable-next-line import/prefer-default-export
export const useProductStore = defineStore('product', {
  state: () => {
    return {
      userMenu: [],
      menuData: menu,
      initProduct: [],
      activeProduct: {},
      activeMeal: {},
    };
  },
  actions: {
    set_menu_data() {
      // const data = {
      //   pageNum: 1,
      //   pageSize: 100000,
      //   queryKey: 'status',
      //   queryValue: 1,
      // };
      // getProductPageList(data).then((res) => {
      //   try {
      //     const { code, data } = res;
      //     if (data && code && code === '000000') {
      //       this.set_menu(data.list);
      //     }
      //   } catch (e) {
      //     console.log(e);
      //   }
      // });
      // this.set_menu();
    },
    set_menu(list) {
      this.initProduct = list;
      this.userMenu = [this.menuData[0].children[0]];
      this.accountMenu = [];
      list.forEach((val, idx) => {
        if ([1, 2].includes(val.type)) {
          this.userMenu.push({
            id: 12 + idx,
            title: `${val.name}账号`,
            type: 2,
            // path: `/adp/${encodeURIComponent(val.name)}/${val.type}/${val.id}`,
            path: `/${
              val.type == 1 ? 'adp' : 'enterprise'
            }/${encodeURIComponent(val.name)}/${val.type}/${val.id}`,
            icon: '',
            sort: 12 + idx,
          });
        }

        if (val.type === 4) {
          this.accountMenu.push({
            id: 61,
            title: '云管后台账号',
            type: 2,
            path: `/adp/${encodeURIComponent('云管后台')}/${val.type}/${
              val.id
            }`,
            icon: '',
            sort: 61,
          });
        }
      });
      this.menuData[0].children = this.userMenu;
      this.menuData[this.menuData.length - 1].children = [this.accountMenu[0]];
    },
    set_active_product(data) {
      this.activeProduct = data;
    },
    set_active_meal(data) {
      this.activeMeal = data;
    },
  },
});
